package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RuntimeAdvice {

    @Pointcut("execution(* com.itheima.service..find*(..))")
    public void pt() {
    }

    @Around("pt()")
    public Object runtimeAround(ProceedingJoinPoint pjp) throws Throwable {
        //获取执行签名信息
        Signature signature = pjp.getSignature();
        //通过签名获取执行类型
        String className = signature.getDeclaringTypeName();
        //通过签名获取执行方法名
        String methodName = signature.getName();

        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            pjp.proceed();
        }
        long endTime = System.currentTimeMillis();
        System.out.println(className + ":" + methodName + "执行万次用了:" + (endTime - startTime) + "秒");
        return null;
    }
}
